package com.apes.fn.server.vehicleFile.model;

import com.apes.fn.server.vehicleFile.server.vehicleFileUploadProcess.CommonUploadProcess;
import com.apes.fn.server.vehicleFile.server.vehicleFileUploadProcess.Process.YunnanUploadProcess;
import com.apes.fn.server.vehicleFile.server.vehicleFileUploadProcess.Process.ZhejiangUploadProcess;
import com.apes.framework.api.SpringManager;
import org.springframework.util.Assert;

import java.util.Arrays;

/**
 * @program: apes-server
 * @description:
 * @author: czs
 * @create: 2023-11-02 14:43
 **/
public enum VehicleFileAreaEnum {
    /**
     * 云南
     */
    YUNNAN("yunnan", "云南", SpringManager.getBean(YunnanUploadProcess.class)),
    TONGYONG("tongyong", "通用", SpringManager.getBean(ZhejiangUploadProcess.class)),
    ZHEJIANG("zhejiang", "浙江", SpringManager.getBean(ZhejiangUploadProcess.class))
    ;

    private String code;

    public String getName() {
        return name;
    }

    private String name;
    private CommonUploadProcess uploadProcess;

    VehicleFileAreaEnum(String code, String name, CommonUploadProcess uploadProcess) {
        this.code = code;
        this.name = name;
        this.uploadProcess = uploadProcess;
    }


    public static CommonUploadProcess codeFind(String code){
        VehicleFileAreaEnum vehicleFileAreaEnum1 = Arrays.stream(VehicleFileAreaEnum.values()).filter(vehicleFileAreaEnum -> {
            return vehicleFileAreaEnum.code.equals(code);
        }).findFirst().orElse(null);
        Assert.notNull(vehicleFileAreaEnum1,"没有对应的处理器");
        return vehicleFileAreaEnum1.uploadProcess;
    }
    public static CommonUploadProcess nameFind(String name){
        VehicleFileAreaEnum vehicleFileAreaEnum1 = Arrays.stream(VehicleFileAreaEnum.values()).filter(vehicleFileAreaEnum -> {
            return vehicleFileAreaEnum.name.equals(name);
        }).findFirst().orElse(null);
        Assert.notNull(vehicleFileAreaEnum1,"没有对应的处理器");
        return vehicleFileAreaEnum1.uploadProcess;

    }
}
